﻿using Avalonia.Controls.Notifications;
using SukiUI.Toasts;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AutojsController.Helpers
{
    /// <summary>
    /// 注意：由于只有SukiWindow上才有SukiToastHost组件，所以如果想在Dialog上弹出消息，必须使用SukiWindow的Dialog而非UserControl
    /// </summary>
    public static class SukiToast
    {
        public static void Show(ISukiToastManager toastManager, string message, NotificationType notificationType, int waitSeconds)
        {
            toastManager.CreateToast().WithContent(message)
                .OfType(notificationType).Dismiss().After(TimeSpan.FromSeconds(waitSeconds))
                .Dismiss().ByClicking().Queue();
        }

        public static void Info(ISukiToastManager toastManager, string message, int waitSeconds = 1)
        {
            Show(toastManager, message, NotificationType.Information, waitSeconds);
        }

        public static void Warn(ISukiToastManager toastManager, string message, int waitSeconds = 1)
        {
            Show(toastManager, message, NotificationType.Warning, waitSeconds);
        }

        public static void Error(ISukiToastManager toastManager, string message, int waitSeconds = 1)
        {
            Show(toastManager, message, NotificationType.Error, waitSeconds);
        }
    }

    public static class FileHelper
    {
        public static async Task CopyAsync(string src, string dst)
        {
            int buffer = 1024 * 1024;
            using var srcStream = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.Read, buffer, true);
            using var dstStream = new FileStream(dst, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write, buffer, true);
            await srcStream.CopyToAsync(dstStream);
        }
    }
}
